export const GET_SONG_URL = "GET_SONG_URL";
export const GET_SONG_URL_SUCCESS = "GET_SONG_URL_SUCCESS";
export const GET_SONG_URL_FAILED = "GET_SONG_URL_FAILED";

export interface IGetSongUrlAction {
  type: typeof GET_SONG_URL;
  payload: string;
}

export interface ISongUrl {
  id: number;
  url: string;
  br: number;
  size: number;
  md5: string;
  code: number;
  expi: number;
  type: string;
  gain: number;
  fee: number;
  payed: number;
  flag: number;
  canExtend: boolean;
  urlSource: number;
}

export interface ISongUrlResult {
  code: number;
  data: ISongUrl[];
}

export interface IGetSongUrlSuccessAction {
  type: typeof GET_SONG_URL_SUCCESS;
  payload: ISongUrlResult;
}

export interface IGetSongUrlFailedAction {
  type: typeof GET_SONG_URL_FAILED;
  payload: string;
}

export const getSongUrl = (songId: string): IGetSongUrlAction => {
  return {
    type: GET_SONG_URL,
    payload: songId,
  };
};

export const getSongUrlSuccess = (
  payload: ISongUrlResult
): IGetSongUrlSuccessAction => {
  return {
    type: GET_SONG_URL_SUCCESS,
    payload,
  };
};

export const getSongUrlFailed = (payload: string): IGetSongUrlFailedAction => {
  return {
    type: GET_SONG_URL_FAILED,
    payload,
  };
};

export type SongUrlUnionType =
  | IGetSongUrlAction
  | IGetSongUrlSuccessAction
  | IGetSongUrlFailedAction;
